<template>
	<u-tabbar activeColor="#252525" :value="tabVal" :border="false" fixed class="tabbar-father">
		<u-tabbar-item v-for="(item,index) in tabBarList" :key="item.text" :name="item.url" 
			:badge="index==3?num:0" :icon="tabVal===item.url?item.actIcon:item.icon" @click="tabclick(item)">

		</u-tabbar-item>
	</u-tabbar>
</template>

<script>
	import {
		allUnread
	} from "../../api/my.js";
	import {
		mapActions
	} from "vuex";
	export default {
		props: {
			path: {
				type: String,
				default: ''
			},
			tabBarList: {
				type: Array,
				default: () => uni.getStorageSync('tabBarList') || []
			},
			// num: {
			// 	type: Number,
			// 	default: 0
			// },
		},
		data() {
			return {
				tabs: [],
				tabVal: '',
				num: 0,
				timer: null//定时器名称
			}
		},
		created() {
			this.tabVal = this.path
			console.log(this.path);
			let that =this
			that.one()

			this.timer = setInterval(function() {
				that.one()
			}, 1500);
			
		},
		onHide() {
			//离开页面前清除计时器
			// console.log('onHide');
			clearInterval(this.timer);
			this.timer = null;
		},
		mounted() {
			
		},
		methods: {
			...mapActions([
				"pageUpdateNotice"
			]),
			tabclick(item) {
				if (item.show) {
					this.pageUpdateNotice()
				}
				uni.switchTab({
					url: item.url,
					fail(e) {
						console.log(e);
					}
				})
			},
			//获取全部未读
			async one(id) {
				const res = await allUnread().then(res => {
					this.num = res.data
					console.log('获取总未读数',this.num);
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
// /deep/.u-tabbar__content{
// 	    background-color: rgba(0,0,0,0) !important;
// }
</style>